package com.yswee.mallnavi.view.info;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.clickedtab.ClickedTabView;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.entity.info.CategoryEntity;
import com.yswee.mallnavi.view.brand.BrandView;
import com.yswee.mallnavi.view.coupon.CouponView;
import com.yswee.mallnavi.view.food.FoodView;
import com.yswee.mallnavi.view.intro.IntroView;
import com.yswee.mallnavi.view.member.MemberView;
import com.yswee.mallnavi.view.navi.NaviView;
import com.yswee.mallnavi.view.park.ParkView;

public class IndexView extends ClickedTabView {

    @ViewInject
    private TabBar uvtabbar;
    @ViewInject
    private TextView tvnameen;

    private NaviView mNaviView;
    private ParkView mParkView;
    private MemberView mMemberView;
    private IntroView mIntroView;
    private BrandView mBrandView;
    private FoodView mFoodView;
    private CouponView mCouponView;

    private int mInitializeTabIndex;

    public void setInitializeTabIndex(int index) {
        mInitializeTabIndex = index;
    }

    @Override
    protected int getInitializeTabIndex() {
        return mInitializeTabIndex;
    }

    public IndexView(Context context) {
        super(context);
    }

    public IndexView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.view_info;
    }

    @Override
    protected int getTabBarResID() {
        return R.id.uvtabbar;
    }

    @Override
    protected int getTabContainerResID() {
        return R.id.uvcontainer;
    }

    @Override
    protected int getTabCount() {
        return 7;
    }

    @Override
    protected View getTabView(int index) {
        switch(index) {
            case 0:
                if (mNaviView == null) {
                    mNaviView = new NaviView(mContext);
                    mNaviView.setFloorChanged(new NaviView.IFloorChanged() {
                        @Override
                        public void onFloorChanged(CategoryEntity categoryEntity) {
                            uvtabbar.setLogoResId(categoryEntity.getIconResId(false));
                        }
                    });
                }
                return mNaviView;
            case 1:
                if (mParkView == null) {
                    mParkView = new ParkView(mContext);
                }
                return mParkView;
            case 2:
                if (mMemberView == null) {
                    mMemberView = new MemberView(mContext);
                }
                return mMemberView;
            case 3:
                if (mIntroView == null) {
                    mIntroView = new IntroView(mContext);
                }
                return mIntroView;
            case 4:
                if (mBrandView == null) {
                    mBrandView = new BrandView(mContext);
                }
                return mBrandView;
            case 5:
                if (mFoodView == null) {
                    mFoodView = new FoodView(mContext);
                }
                return mFoodView;
            case 6:
                if (mCouponView == null) {
                    mCouponView = new CouponView(mContext);
                }
                return mCouponView;
            default:
                return new View(mContext);
        }
    }

    @Override
    protected void onBindListener() {
        super.onBindListener();
    }

    @Override
    protected void onApplyData() {
        super.onApplyData();
    }

    @Override
    public void onTabChanged(int index) {
        super.onTabChanged(index);
        switch (index) {
            case 1:
                tvnameen.setText(R.string.park_en_r);
                break;
            case 2:
                tvnameen.setText(R.string.member_en_r);
                break;
            case 3:
                tvnameen.setText(R.string.intro_en_r);
                break;
            case 4:
                tvnameen.setText(R.string.brand_en_r);
                break;
            case 5:
                tvnameen.setText(R.string.food_en_r);
                break;
            case 6:
                tvnameen.setText(R.string.coupon_en_r);
                break;
            case 0:
            default:
                tvnameen.setText(R.string.navi_en_r);
                break;
        }
    }
}
